package cn.itcast.service.impl;

import cn.itcast.dao.AddressDao;
import cn.itcast.pojo.Address;
import cn.itcast.service.AddressService;
import com.alibaba.dubbo.config.annotation.Service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Map;

@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;

    /**
     * 查询所有的医院
     *
     * @return
     */
    @Override
    public List<Address> findAll() {
        return this.addressDao.findAllAddress();
    }
    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Address> pageQuery() {

        List<Address>list = addressDao.findAll();
        return list;
    }

    /**
     * 新增
     * @param address
     * @return
     */
    @Override
    public int add(Address address) {

        if (ObjectUtils.isEmpty(address.getId())){
            return addressDao.add(address) ;
        }else {
            return this.updateById(address);
        }
    }

    /**
     * 根据id修改
     * @param
     * @return
     */
    @Override
    public int updateById(Address address) {

        return addressDao.updateById(address);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Address findById(Integer id) {

        return addressDao.findById(id);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Override
    public Boolean delete(Integer id) {
        return addressDao.delete(id);
    }

    /**
     * 是否启用
     * @param id
     * @param enable
     * @return
     */
    @Override
    public void updateEnable(Integer id ,Integer enable) {
        addressDao.updateEnable(id,enable);
    }
}
